// packageA/mycomponent/goods_telephone_charges_pro/goods_telephone_charges_pro.js
var app = getApp();
var timeout = false;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    prop_goods_info: {
      type: null, //父组件的商品详情数据
    },
    goodsId: {
      type: Number,
    },
    goodsType: {
      type: String,
    },
    hoet: {
      type: null,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgPath: app.globalData.imgPath,
    goodsInfo: {},

    rechargeType: {},
    rechargeItem: {},
    rechargeSpecId: 0,

    displayOptions: [],
    optionsId: 0,

    show1: false,
    service_QRcode: "",
    service_mobile: "",
    cservice: "",

    //猜你喜欢
    likeArr: [],
    swipeIndex: 0,

    mobile: "",

    bannerUrl: "",

    posterShow: false,
    mobileCity: ""

  },
  ready() {
    let prop_goods_info = this.properties.prop_goods_info;
    let changeData = {};
    let goodsInfo = this.data.goodsInfo = prop_goods_info.get_goods;
    let rechargeType = goodsInfo.has_many_specs[0];
    this._handClickSpecs(rechargeType.specitem[0]);
    changeData.goodsInfo = goodsInfo;
    changeData.rechargeType = rechargeType;
    //轮播图
    if (prop_goods_info && prop_goods_info.plugin && prop_goods_info.plugin.phoneBillPro) {
      changeData.bannerUrl = prop_goods_info.plugin.phoneBillPro.banner;
    }

    //客服相关
    if (prop_goods_info.customer_service) {
      // 客服
      changeData.service_QRcode = prop_goods_info.customer_service.service_QRcode;
      changeData.service_mobile = prop_goods_info.customer_service.service_mobile;
      changeData.cservice = prop_goods_info.customer_service.cservice;
    }

    //猜你喜欢
    let show_push = goodsInfo.show_push.slice(0, 30);
    let likeArr = [];
    show_push.forEach(function (item, index) {
      var num = Math.floor(index / 6); //
      if (!likeArr[num]) {
        likeArr[num] = [];
      }
      likeArr[num].push(item); //将数据添加到数组里
    });
    changeData.likeArr = likeArr;
    this.setData(changeData);
  },
  /**
   * 组件的方法列表
   */
  methods: {
    tapInpC(){
      if(this.data.mobile.length == 11){
        let urlStr = app.getNetAddresss("plugin.phone-bill-pro.frontend.controller.phone-query.get-phone-info");
        app._getNetWork({
            url: urlStr,
            data: {
            mobile: this.data.mobile
            },
            success: (resdata) => {
                var res = resdata.data;
                timeout = false
                if (res.result == 1) {
                    this.setData({
                        mobileCity:`${res.data.city} ${res.data.isp}`
                    })
                }
            },
            fail:()=>{
                timeout = false
            }
        });
      }else{
        this.setData({
          mobileCity:""
        })
      }
    },
    handClickSpecs(evt) {
      let item = evt.currentTarget.dataset.item;
      this._handClickSpecs(item);
    },
    _handClickSpecs(item) {
      if (this.data.rechargeSpecId == item.id) return;
      let has_many_options = this.data.goodsInfo.has_many_options;
      let arr = [];
      for (let i = 0; i < has_many_options.length; i++) {
        if (has_many_options[i].specs.indexOf(item.id) >= 0) {
          arr.push(has_many_options[i]);
        }
      }
      this.setData({
        rechargeSpecId: item.id,
        rechargeItem: item,
        displayOptions: arr,
        optionsId: 0
      });
    },

    handClickOptions(evt) {
      let item = evt.currentTarget.dataset.item;
      this.setData({
        optionsId: item.id
      });
    },

    onChangeSwipeIndex(evt) {
      let index = evt.detail.current;
      this.setData({
        swipeIndex: index
      });
    },
    gotoDetailV2(evt){
      let id = evt.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/packageA/detail_v2/detail_v2?id='+id,
      });
    },
    gotoChat(evt) {
      let url = evt.currentTarget.dataset.cservice + "&goods_id=" + this.data.goodsId;
      wx.navigateTo({
        url: url,
        fail: (err) => {
          app.tips("客服路由出错");
        }
      });
    },

    setCserviceFlag(){
      this.setData({
        show1:!this.data.show1
      });
    },

    gotoOrderList(){
      wx.navigateTo({
        url: '/packageA/member/myOrder_v2/myOrder_v2',
      });
    },

    gotoIndex(){
      wx.reLaunch({
        url: '/packageG/index/index',
      });
    },

    setPosterShow(){
      this.setData({
        posterShow:true
      });
    },
    setTopping() {
      wx.pageScrollTo({
        scrollTop: 0
      });
    },

    sendRecharge() {
      // 手机慢充
      let {mobile,goodsId,optionsId} = this.data;
      if (!mobile) {
        app.tips("请输入充值手机号码！");
        return false;
      } else {
        let reg_txt = /^[1][0-9]{10}$/;
        if (!reg_txt.test(mobile)) {
          app.tips("请输入正确的充值手机号码！");
          return false;
        }
      }
      if (optionsId <= 0) return app.tips("请选择规格ID");
 
      wx.navigateTo({
        url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2&total=1&&goodsId=" + goodsId + "&optionsId=" + optionsId + "&mobile=" + mobile,
      });
      //this.$router.push(this.fun.getUrl("goodsorder", {}, json_data));
    },





  }
});